package org.grottarossa.ui.core.controls.document.upload;

import java.util.ResourceBundle;

import org.grottarossa.template.drivers.components.tokens.DocumentManagementId;
import org.grottarossa.ui.core.ApplicationSession;
import org.grottarossa.ui.core.StylesConstants;
import org.grottarossa.ui.core.base.BasePanelView;

import com.vaadin.terminal.Sizeable;


/***
 * Controllo per il caricamento di un file sul back-end
 * @author 
 *
 */
public class UploadDocument extends BasePanelView<UploadDocumentPresenter>
{
	/*** Gestore dei caricamenti ***/
	private DocumentUploader m_uploader;

	public UploadDocument(ApplicationSession appSession, ResourceBundle localizer, DocumentUploader uploader)
	{
		super(appSession, localizer);
		m_uploader = uploader;
		m_uploader.setMessageNotifier(this);
		initializeComponents();
	}

	@Override
	protected void initializeComponents()
	{
		getLayout().setWidth(100, Sizeable.UNITS_PERCENTAGE);

		m_uploader.setWidth(100, Sizeable.UNITS_PERCENTAGE);
		m_uploader.addStyleName(StylesConstants.UPLOADER);
		addComponent(m_uploader);
	}

	public void addObserver(IDocumentUploaderObserver observer)
	{
		m_presenter.addObserver(observer);
	}

	public void initialize(DocumentManagementId documentID)
	{
		m_uploader.addObserver(m_presenter);
		m_uploader.setDocument(documentID);
	}
}
